class BlogPost < ActiveRecord::Base
  has_many  :comments
  
  belongs_to  :show
  belongs_to  :song
  belongs_to  :video
  belongs_to  :photo
  belongs_to  :user
  
  validates_presence_of :user
  validates_presence_of :text
  validates_presence_of :title
  
  has_friendly_id       :title, :use_slug => true

  after_destroy         :delete_comments
  
protected
  def delete_comments
    (self.comments.each {|comment| comment.destroy}) unless self.comments.empty?
  end
end
